<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('kh_form')" />
</head>
<body class="white-bg">
	<div class="main-content">
		<form class="form-horizontal" id="form">
			<input id="pageFlag" name="pageFlag" type="hidden" th:value="${kh.pageFlag}" />
			<input id="id" name="id" type="hidden" th:value="${kh.id}" />
			<input id="type" name="type" type="hidden" th:value="${kh.type}" />
			<input id="khz" name="khz" type="hidden" th:value="${kh.khz}" />
			<input id="reserveStatus" name="reserveStatus" type="hidden" th:value="${kh.reserveStatus}" />
			<input id="createDept.deptId" name="createDept.deptId" type="hidden" th:value="${kh.createDept.deptId}" />
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-3 control-label is-required">考核月份：</label>
						<div class="col-sm-8">
							<input name="monthId" id="monthId" th:value="${kh.monthId}" class="form-control" type="text" required />
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-3 control-label is-required">考核组：</label>
		                <div class="col-sm-8">
		                    <select id="khz" name="khz" class="form-control m-b" disabled="disabled">
		                        <option value="">请选择</option>
		                        <option th:each="dict : ${khzList}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
									th:selected="${kh.khz == dict.dictValue}"></option>
		                    </select>
		                </div>
					</div>
				</div>
				<!-- 
				<div class="col-sm-6">
					<label class="col-sm-3 control-label is-required">填报类型：</label>
	                <div class="col-sm-8">
	                    <select class="form-control m-b" required
	                        th:with="dicts=${@dict.getType('rate_kh_type')}" disabled="disabled">
	                        <option value="">请选择</option>
	                        <option th:each="dict : ${dicts}" th:selected="${kh.type == dict.dictValue}"
	                            th:text="${dict.dictLabel}" th:value="${dict.dictValue}" />
	                    </select>
	                </div>
				</div>
				 -->
				<div class="col-sm-6" th:if="${'ZB' == kh.type || 'KHB_ZB' == kh.type}">
					<input id="dept.deptId" name="dept.deptId" type="hidden" th:value="${kh.dept.deptId}" />
					<label class="col-sm-3 control-label is-required">被考核部门：</label>
					<div class="col-sm-8">
						<input th:value="${kh.dept.deptName}" class="form-control" type="text" readonly="readonly" />
					</div>
				</div>
				<div class="col-sm-6" th:if="${'DB' == kh.type}">
					<label class="col-sm-3 control-label is-required">被考核部门：</label>
	                <div class="col-sm-8">
	                    <select id="dept.deptId" name="dept.deptId" class="form-control m-b" required>
	                        <option value="">请选择</option>
	                        <option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"
	                            th:selected="${kh.dept.deptId == dept.deptId}" />
	                    </select>
	                </div>
				</div>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="ruleTable">
					<thead><tr>
						<th style="width:10%">类别</th>
						<th style="width:10%">项目</th>
						<th style="width:5%">序号</th>
						<th style="width:5%">分值</th>
						<th style="width:30%">内容及标准</th>
						<th style="width:5%">方式</th>
						<th style="width:5%">打分</th>
						<th style="width:25%">打分原因</th>
						<th style="width:5%">责任人</th>
					</tr></thead>
					<tbody>
						<tr th:each="khRule:${khRuleList}">
							<td class="col-sm-1">
								<input type="hidden" th:id="${'kh_rule_id_' + khRule.relaId}" th:name="${'kh_rule_id_' + khRule.relaId}"
									th:value="${khRule.id}" />
								<div style="display:none;" th:if="${'ADD' == kh.pageFlag}">
									<input type="hidden" th:id="${'kh_rule_ruleId_' + khRule.relaId}" th:name="${'kh_rule_ruleId_' + khRule.relaId}"
										th:value="${khRule.ruleId}" />
									<input type="hidden" th:id="${'kh_rule_khz_' + khRule.relaId}" th:name="${'kh_rule_khz_' + khRule.relaId}"
										th:value="${khRule.khz}" />
									<input type="hidden" th:id="${'kh_rule_type_' + khRule.relaId}" th:name="${'kh_rule_type_' + khRule.relaId}"
										th:value="${khRule.type}" />
									<input type="hidden" th:id="${'kh_rule_deptId_' + khRule.relaId}" th:name="${'kh_rule_deptId_' + khRule.relaId}"
										th:value="${khRule.dept.deptId}" />
									<input type="hidden" th:id="${'kh_rule_lb_' + khRule.relaId}" th:name="${'kh_rule_lb_' + khRule.relaId}"
										th:value="${khRule.lb}" />
									<input type="hidden" th:id="${'kh_rule_xm_' + khRule.relaId}" th:name="${'kh_rule_xm_' + khRule.relaId}"
										th:value="${khRule.xm}" />
									<input type="hidden" th:id="${'kh_rule_xh_' + khRule.relaId}" th:name="${'kh_rule_xh_' + khRule.relaId}"
										th:value="${khRule.xh}" />
									<input type="hidden" th:id="${'kh_rule_fz_' + khRule.relaId}" th:name="${'kh_rule_fz_' + khRule.relaId}"
										th:value="${khRule.fz}" />
									<input type="hidden" th:id="${'kh_rule_nr_' + khRule.relaId}" th:name="${'kh_rule_nr_' + khRule.relaId}"
										th:value="${khRule.nr}" />
									<input type="hidden" th:id="${'kh_rule_fs_' + khRule.relaId}" th:name="${'kh_rule_fs_' + khRule.relaId}"
										th:value="${khRule.fs}" />
								</div>
								<span th:text="${khRule.lb}"></span>
							</td>
							<td class="col-sm-2">
								<span th:text="${khRule.xm}"></span>
							</td>
							<td class="col-sm-1">
								<span th:text="${khRule.xh}"></span>
							</td>
							<td class="col-sm-1">
								<span th:text="${khRule.fz}"></span>
							</td>
							<td class="col-sm-2">
								<span th:text="${khRule.nr}"></span>
							</td>
							<td style="col-sm-1">
								<span th:text="${khRule.fs}"></span>
							</td>
							<td class="col-sm-1">
								<input type="text" class="form-control input-sm" th:id="${'kh_rule_kf_' + khRule.relaId}" th:name="${'kh_rule_kf_' + khRule.relaId}"
									th:value="${khRule.kf}" />
							</td>
							<td class="col-sm-2">
								<textarea th:name="${'kh_rule_remark_' + khRule.relaId}" th:id="${'kh_rule_remark_' + khRule.relaId}"
									th:text="${khRule.remark}"
									rows="3" maxlength="400" class="form-control"></textarea>
							</td>
							<td class="col-sm-1">
								<textarea th:id="${'kh_rule_zrr_' + khRule.relaId}" th:name="${'kh_rule_zrr_' + khRule.relaId}"
									th:text="${khRule.zrr}" rows="2" maxlength="20"
									class="form-control input-sm"></textarea>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
			<div style="clear:both;"></div>
			<h4 class="form-header h4" th:if="${'1' == showCheckResult}" style="margin-top:20px;">审批信息</h4>
			<div class="row" th:if="${'1' == showCheckResult}">
				<div class="col-sm-6">
					<label class="col-sm-4 control-label is-required">审批结果：</label>
					<div class="col-sm-6">
						<label class="radio-box"> <input type="radio" name="checkResult" value="APPROVED" /> 通过 </label>
						<label class="radio-box"> <input type="radio" name="checkResult" value="REJECTED" /> 拒绝 </label>
					</div>
				</div>
				<div class="col-sm-6">
					<label class="col-sm-4 control-label">审批意见：</label>
					<div class="col-sm-6">
						<input class="form-control" type="text" name="checkDesc" id="checkDesc" />
					</div>
				</div>
				<div class="col-sm-6" th:if="${'KHZ' == kh.pageFlag}">
					<div class="form-group">
						<label class="col-sm-4 control-label is-required">分管领导：</label>
						<div class="col-sm-6">
							<select class="form-control" name="fgldChecker.userId" id="fgldChecker.userId" th:with="fgldList=${fgldList}">
								<option value=""></option>
								<option th:each="item : ${fgldList}" th:text="${item.userName}" th:value="${item.userId}"
									th:selected="${kh.fgldChecker.userId == item.userId}"></option>
							</select>
						</div>
					</div>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script>
		var prefix = ctx + "rate/kh";
		var pageFlag = '[[${kh.pageFlag}]]';
		
		$(function() {
			$("#monthId").datetimepicker({
				format: 'yyyy-mm',
				weekStart: 1,
				autoclose: true,
				startView: 3,
				minView: 3
			});
			
			
			$("#ruleTable").bootstrapTable();
			$("#ruleTable th").addClass("text-center");
			$("#ruleTable td").addClass("text-center");
			// $(".no-records-found").hide();
			
			if ("ADD" == pageFlag || "EDIT" == pageFlag) {
			} else if ("VIEW" == pageFlag) {
				$("#form input[type='text']").prop("disabled", true);
				$("#form textarea").prop("disabled", true);
				$("#form select").prop("disabled", true);
			} else if ("KHZ" == pageFlag || "FGLD" == pageFlag || "HZ" == pageFlag) {
			}
		});
		
		function submitHandler() {
			if (pageFlag == "ADD" || pageFlag == "EDIT") {
				if ($.validate.form()) {
					$.modal.confirm("确定保存数据？", function() {
						$.operate.save(prefix + "/save", $('#form').serialize());
					});
				}
			} else if (pageFlag == "KHZ" || pageFlag == "FGLD" || pageFlag == "HZ") {
				var checkedResult = $("input[name='checkResult']:checked").val();
				if (checkedResult == null) {
					$.modal.alertWarning("请选择审批结果！");
					return false;
				}
				
				/**
				if ($("input[name='checkDesc']").val() == "") {
					$.modal.alertWarning("请填写审批意见！");
					return false;
				}
				**/
				
				if (pageFlag == "KHZ") {
					if ("APPROVED" == checkedResult && !$("#fgldChecker\\.userId").val()) {
						$.modal.alertWarning("请选择分管领导！");
						return false;
					}
				}
				
				if ($.validate.form()) {
					$.operate.save(prefix + "/submitCheck", $('#form').serialize());
				}
			} else {
				var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
				parent.layer.close(index); //再执行关闭
				return true;
			}
		}
	</script>
</body>
</html>
